class Node1{
    public int val;
    public Node1 next;

    public Node1(int val) {
        this.val = val;
    }
}

public class Test3 {

    public static int operation(int n, int m) {//n为人数，m为每次走多少步
        Node1 head = new Node1(0);
        Node1 cur = head;
        int count = 1;
        while (count < n) {
            Node1 node1 = new Node1(count++);
            cur.next = node1;
            cur = cur.next;
        }

        int k = m;
        while (n > 1) {
            k = m - 2;
            while (k > 0) {
                cur = cur.next;
                k--;
            }
            cur.next = cur.next.next;
            cur = cur.next;
        }

        return cur.val;
    }
}
